Automated refactoring of super-class method invocations to the Template Method design pattern
نویسندگان
چکیده
Context: Implementation inheritance, i.e., overriding of concrete method implementations through subtyping, is prone to potential class contract violations. Call Super is a code pattern that employs implementation inheritance for extending a method’s behaviour. In Call Super the overriding method includes in its body an invocation to the overridden method. Template Method is a design pattern that enables extensions to a multi-step procedure without overriding its concrete implementation. Instead, subclasses provide different variants of the template method’s behaviour through implementation of abstract method definitions (interface inheritance). Objective: This work studies the automated refactoring of Call Super to Template Method, contributing, thus, to replacement of implementation inheritance with interface inheritance. Method: We introduce an algorithm for the discovery of refactoring candidates that is based on an extensive set of refactoring preconditions. Moreover, we specify the source code transformation for refactoring a Call Super instance to Template Method. An implementation of the proposed approach is evaluated on a set of open source Java projects. Results: The evaluation results highlight (a) the frequent occurrence of the Call Super pattern among method overridings, (b) the potential provided by our method for discovery and elimination of several non-trivial Call Super instances and (c) the resulting code improvement, as reflected by the Specialization Index metric and the alignment of refactored code with the programmer’s intent. The application of all refactorings identified on a set of benchmark projects and the successful execution of their test suites provide empirical evidence on the soundness of the refactoring procedure. Runtime performance results support the scalability of the proposed method. Conclusion: The proposed method automates the replacement of implementation inheritance with interface inheritance through refactoring Call Super instances to Template Method. The empirical evaluation of the method supports its applicability, soundness and runtime efficiency.
منابع مشابه
Automated refactoring to the Null Object design pattern
Context: Null-checking conditionals are a straightforward solution against null dereferences. However, their frequent repetition is considered a sign of poor program design, since they introduce source code duplication and complexity that impacts code comprehension and maintenance. The Null Object design pattern enables the replacement of null-checking conditionals with polymorphic method invoc...
متن کاملAutomated refactoring to the Strategy design pattern
Context: The automated identification of code fragments characterized by common design flaws (or ‘‘code smells’’) that can be handled through refactoring, fosters refactoring activities, especially in large code bases where multiple developers are engaged without a detailed view on the whole system. Automated refactoring to design patterns enables significant contributions to design quality eve...
متن کاملComposite Refactorings: The Next Refactoring Rubicons
The industry crossed the first refactoring rubicon, namely Extract Method, more than a decade ago. Today, all mainstream Integrated Development Environments (IDEs) support this refactoring, and empirical studies have shown that Extract Method is one of the most frequently used automated refactorings. Although complex refactorings are more tedious and error-prone, studies have shown that program...
متن کاملMORE: A multi-objective refactoring recommendation approach to introducing design patterns and fixing code smells
Refactoring is widely recognized as a crucial technique applied when evolving object-oriented software systems. If applied well, refactoring can improve different aspects of software quality including readability, maintainability and extendibility. However, despite its importance and benefits, recent studies report that automated refactoring tools are underused much of the time by software deve...
متن کاملRefactoringScript: A Script and Its Processor for Composite Refactoring
Refactoring is widely recognized as a method to improve the internal qualities of source code. However, manual refactoring is time-consuming and error-prone. Consequently, many tools to support automated refactoring have been suggested, but most support only unit and simple refactoring, making it difficult to perform composite refactoring (e.g., introducing a design pattern) where a refactoring...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
- Information & Software Technology
دوره 82 شماره
صفحات -
تاریخ انتشار 2017